<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 1. new 关键词
    // 2. 如何创建构造函数
    // 3. 公有的属性和方法怎么放 => prototype
    // 4. 实例化对象如何访问原型对象    [[prototype]]  prototype
    // 5. 实例化对象如何找到创建它的构造函数  constructor

    // this的指向

    console.dir(Array)

    Array.prototype.myslice = function (startIndex, endIndex) {
        // this -> 调用此方法的实例化对象 ()
        var list = [];
        for (var i = startIndex; i < endIndex; i++) {
            var item = this[i];
            list.push(item);
        }
        return list;
    }

    Array.prototype.myEach = function (fn) {
        // this -> 调用此方法的实例化对象 ()
        for (var i = 0; i < this.length; i++) {
            var item = this[i];
            var index = i;
            var array = this;
            fn(item, index, array)
        }
    }

    var arr = [1, 2, 3];
    console.log(arr);
    console.log(arr.constructor === Array);

    console.log(arr.myslice(1, 2));

    arr.myEach(function (item, index, array) {
        console.log(item, index, array);
    })

    // var brr = [4, 5, 6];
    // console.log(brr);
    // console.log(brr.constructor === Array);

    // console.log(arr.myslice(2, 3));

</script>

</html>